#ifndef __W25QXX_H
#define __W25QXX_H

#include "bsp.h"

#ifdef USE_SPI
//W25X系列/Q系列芯片列表	   
//W25Q80  ID  0XEF13
//W25Q16  ID  0XEF14
//W25Q32  ID  0XEF15
//W25Q64  ID  0XEF16	
//W25Q128 ID  0XEF17	
//W25Q256 ID  0XEF18
#define W25Q80 	0XEF13 	
#define W25Q16 	0XEF14
#define W25Q32 	0XEF15
#define W25Q64 	0XEF16
#define W25Q128	0XEF17
#define W25Q256 0XEF18


////////////////////////////////////////////////////////////////////////////////// 
//指令表
#define Flash_WriteEnable		0x06 
#define Flash_WriteDisable		0x04 
#define Flash_ReadStatusReg1		0x05 
#define Flash_ReadStatusReg2		0x35 
#define Flash_ReadStatusReg3		0x15 
#define Flash_WriteStatusReg1    0x01 
#define Flash_WriteStatusReg2    0x31 
#define Flash_WriteStatusReg3    0x11 
#define Flash_ReadData			0x03
#define Flash_QuadRead           0x6B  /* Read from Memory instruction */ 
#define Flash_FastReadData		0x0B 
#define Flash_FastReadDual		0x3B 
#define Flash_FastReadQuad		0x6B 
#define Flash_PageProgram		0x02 
#define Flash_QuadWrite          0x32  /* Quad Write to Memory instruction */
#define Flash_BlockErase			0xD8 
#define Flash_SectorErase		0x20 
#define Flash_ChipErase			0xC7 
#define Flash_PowerDown			0xB9 
#define Flash_ReleasePowerDown	0xAB 
#define Flash_DeviceID			0xAB 
#define Flash_ManufactDeviceID	0x90 
#define Flash_ManufactDeviceID_QSPI	0x94 
#define Flash_JedecDeviceID		0x9F 
#define Flash_Enable4ByteAddr    0xB7
#define Flash_Exit4ByteAddr      0xE9

typedef struct _s_spi_flash SPI_FLASH;
struct _s_spi_flash{
    SPI spi;
    OutputPort cs;
    uint16_t flash_type;
    void (*Init)(SPI_FLASH *spi_flash);
    uint16_t(*ReadID)(SPI_FLASH *spi_flash);
    void (*Read)(SPI_FLASH *spi_flash,uint8_t* pBuffer,uint32_t ReadAddr,uint32_t NumByteToRead);  //读取flash
    void (*Write)(SPI_FLASH* spi_flash,uint8_t* pBuffer,uint32_t WriteAddr,uint32_t NumByteToWrite); //写入flash
    void (*Erase_Chip)(SPI_FLASH *spi_flash);
    void (*Erase_Sector)(SPI_FLASH *spi_flash,uint32_t Dst_Addr);
    void(*PowerDown)(SPI_FLASH *spi_flash);
    void(*WakeUp)(SPI_FLASH *spi_flash);

};

SPI_FLASH new_spi_flash(uint32_t spi_gpio,uint32_t sck_pinx,\
						uint32_t miso_pinx,uint32_t mosi_pinx,uint32_t spix,\
						uint32_t cs_gpio,uint32_t cs_pinx);
#endif
#endif
